package cn.niit.pm.service.impl;

import cn.niit.pm.dao.DepartmentMapper;
import cn.niit.pm.entity.Department;
import cn.niit.pm.service.DepartmentService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/* * fahui
 * 部门业务逻辑层实现类（对需要的数据库操作都通过调用DAO层接口实现）
 * */


@Component
@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Resource
    private DepartmentMapper departmentMapper;  //调用部门类DAO层接口
    /*
     *
     * 根据查询条件，查询符合所有条件的部门信息
     * @param department
     * @return*/


    @Override
    public List<Department> selectListByDepartment(Department department) {
        return departmentMapper.selectListByDepartment(department);
    }

    /**
     * 添加部门信息
     * @param department
     * @return*/


    @Override
    public int insertDepartment(Department department) {
        department.setGmtCreate(new Date());
        int rows = departmentMapper.insertDepartment(department);
        return rows;
    }

    /**
     * 根据部门ID查询部门信息
     * @param departmentId
     * @return*/


    public Department selectByDepartmentId(Integer departmentId) {
        return departmentMapper.selectByDepartmentId(departmentId);
    }

    /**
     * 更新部门信息
     *
     * @param department
     * @return*/


    public int updateDepartment(Department department) {
        return departmentMapper.updateDepartment(department);
    }

    /**
     * 删除部门信息（依据ID）
     *
     * @param departmentId
     * @return*/


    public int deleteByDepartmentId(Integer departmentId) {
        return departmentMapper.deleteByDepartmentId(departmentId);
    }
}
